package com.sxt.sys.service.impl;

import com.sxt.sys.domain.Role;
import com.sxt.sys.mapper.RoleMapper;
import com.sxt.sys.service.IRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 老雷
 * @since 2019-08-12
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements IRoleService {

	@Override
	public boolean removeById(Serializable id) {
		boolean removeById = super.removeById(id);
		this.getBaseMapper().deleteRolePermissionByRid(id);
		return removeById;
	}

	@Override
	public List<Integer> queryRolePermissionIdsByRId(Integer id) {
		return this.getBaseMapper().queryRolePermissionIsByRId(id);
	}

	@Override
	public void saveRolePermission(Integer id, Integer[] ids) {
		this.getBaseMapper().deleteRolePermissionByRid(id);
		if(null!=ids&&ids.length>0){
			for(Integer pid : ids) {
				this.getBaseMapper().insertRolePermission(id,pid);
			}
		}
		
	}

	@Override
	public List<Integer> queryRoleUserByUserId(Integer id) {
		return this.getBaseMapper().queryRoleUserByUserId(id);
	}

	@Override
	public List<String> queryRoleNameUserByUserId(Integer id) {
		List<Integer> roleIds = this.getBaseMapper().queryRoleUserByUserId(id);
		if(roleIds.size()==0) {
			return new ArrayList<String>();
		}else {
			List<String> roleNames = this.getBaseMapper().queryRoleNameByIds(roleIds);
			return roleNames;
		}
		
	}
}
